package com.sahala.downimage.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import com.sahala.downimage.dao.IPageDAO;
import com.sahala.downimage.domain.PageDO;

public class PageDAOImpl implements IPageDAO {
	
	@Autowired
	public SqlSessionTemplate sqlSession;

	public SqlSessionTemplate getSqlSession() {
		return sqlSession;
	}

	public void setSqlSession(SqlSessionTemplate sqlSession) {
		this.sqlSession = sqlSession;
	}

	@Override
	public int save(PageDO page) {
		return this.sqlSession.insert("PageDAO.save", page);
	}
	
	@Override
	public PageDO queryByPageId(long pageId) {
		Map<String,Long> params = new HashMap<String,Long>();
		params.put("pageId", pageId);
		PageDO result = this.sqlSession.selectOne("PageDAO.queryByPageId", params);
		return result;
	}

	@Override
	public int deleteBypageId(long pageId) {
		Map<String,Long> params = new HashMap<String,Long>();
		params.put("pageId", pageId);
		return sqlSession.delete("PageDAO.deleteBypageId", params);
	}
}
